package com.czn.shopdemo.model.exception;

import com.czn.shopdemo.model.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.logging.Level;

/**
 * @author Zenan Chen
 * @date 2023/4/3 13:45
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(Exception.class)
    private Result error(Exception e) {
        log.error("【发生异常】{}", e.getMessage());
        return Result.fail();
    }

    @ExceptionHandler(CustomException.class)
    private Result error(CustomException e) {
        log.error("【发生异常】{}", e.getMessage());
        return Result.fail(e.getMessage());
    }
}
